<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Get sorting key for a string</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="collator.getlocale.html">« Collator::getLocale</a></li>
      <li style="float: right;"><a href="collator.getstrength.html">Collator::getStrength »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="class.collator.html">Collator</a></li>
    <li>Get sorting key for a string</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="collator.getsortkey" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Collator::getSortKey</h1>
  <h1 class="refname">collator_get_sort_key</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.2, PHP 7, PHP 8, PECL intl &gt;= 1.0.3)</p><p class="refpurpose"><span class="refname">Collator::getSortKey</span> -- <span class="refname">collator_get_sort_key</span> &mdash; <span class="dc-title">Get sorting key for a string</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-collator.getsortkey-description">
  <h3 class="title">说明</h3>
  <p class="para">
   面向对象风格
  </p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><strong>Collator::getSortKey</strong></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   过程化风格
  </p>
  <div class="methodsynopsis dc-description"><span class="methodname"><strong>collator_get_sort_key</strong></span>(<span class="methodparam"><span class="type"><a href="class.collator.html" class="type Collator">Collator</a></span> <code class="parameter">$object</code></span>, <span class="methodparam"><span class="type">string</span> <code class="parameter">$string</code></span>): <span class="type"><span class="type">string</span>|<span class="type"><span class="type false">false</span></span></span></div>

  <p class="para rdfs-comment">
   Return collation key for a string.
   Collation keys can be compared directly instead of strings, though are implementation
   specific and may change between ICU library versions. Sort keys are generally only
   useful in databases or other circumstances where function calls are extremely expensive.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-collator.getsortkey-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">object</code></dt>

     <dd>

      <p class="para">
       <span class="classname"><a href="class.collator.html" class="classname">Collator</a></span> object.
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">string</code></dt>

     <dd>

      <p class="para">
       The string to produce the key from.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-collator.getsortkey-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">Returns the collation key for the string,  或者在失败时返回 <strong><code>false</code></strong>.</p>
  <div class="warning"><strong class="warning">警告</strong><p class="simpara">此函数可能返回布尔值
<strong><code>false</code></strong>，但也可能返回等同于 <strong><code>false</code></strong> 的非布尔值。请阅读 <a href="language.types.boolean.html" class="link">布尔类型</a>章节以获取更多信息。应使用
<a href="language.operators.comparison.html" class="link">===
运算符</a>来测试此函数的返回值。</p></div>
 </div>


 <div class="refsect1 examples" id="refsect1-collator.getsortkey-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-2290">
    <p><strong>示例 #1 <span class="function"><strong>collator_get_sort_key()</strong></span>example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$s1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'Hello'</span><span style="color: #007700">;<br /><br /></span><span style="color: #0000BB">$coll&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">collator_create</span><span style="color: #007700">(</span><span style="color: #DD0000">'en_US'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$res&nbsp;&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">collator_get_sort_key</span><span style="color: #007700">(</span><span style="color: #0000BB">$coll</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$s1</span><span style="color: #007700">);<br /><br />echo&nbsp;</span><span style="color: #0000BB">bin2hex</span><span style="color: #007700">(</span><span style="color: #0000BB">$res</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程的输出类似于：</p></div>
    <div class="example-contents screen"><br />
     3832404046010901dc08<br />
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-collator.getsortkey-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="collator.sort.html" class="function" rel="rdfs-seeAlso">collator_sort()</a> - Sort array using specified collator</span></li>
    <li class="member"><span class="function"><a href="collator.sortwithsortkeys.html" class="function" rel="rdfs-seeAlso">collator_sort_with_sort_keys()</a> - Sort array using specified collator and sort keys</span></li>
   </ul>
  </p>
 </div>

</div></div></div></body></html>